{include file="common/top" /}
<style>
html{
	background: #ffffff;
}
</style>
<form class="layui-form " action="" style="    background: #fff;">
	<div class="layui-form-item">
		<label class="layui-form-label">绑定端口：</label>
		<div class="layui-col-xs6">
			<div id="test5" class="demo-transfer"></div>
		</div>
	</div>
	<hr />
	<div class="layui-form-item">
		<div class="layui-input-block">
			<input type="hidden"  name="id" value="{$Request.get.id}">
			<input type="hidden"  name="channel_ids" value="">
			<button class="layui-btn"  lay-submit="" lay-filter="demo1">修改 </button>
		</div>
	</div>
	
</form>
<script src="__static/js/xm-select.js" charset="utf-8"></script>
{include file="common/footer" /}
<script>
    var form,layer,laydate,upload,$,transfer;
	layui.use(['form', 'layedit', 'laydate','upload','transfer'], function(){
		  form = layui.form ,layer = layui.layer, laydate = layui.laydate,upload = layui.upload,$ = layui.jquery,transfer = layui.transfer;
		  laydate.render({
			    elem: '#date', //指定元素
			  });
		  //监听提交
		  form.on('submit(demo1)', function(data){
            var articleFrom = data.field;
			layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
			$.post("{:url('save_group')}?t=json",articleFrom,function(data){
				layer.closeAll();
				if (data['code'] == 1) { 
					var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index1); //再执行关闭 
					//父页面数据 ，重新加载
					parent.get_load(data['msg']);

				} else {
					layer.msg(data['msg'], { icon : 5 });
				}
			});
			
			return false;
          });
       
        $(function(){
            var id= {$Request.get.id};
            get_channel(id);
		});
		
        
	});
	//绑定,端口
	function get_channel(id){
		layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
		$.post("{:url('user_list')}?t=json",{id:id},function(data){
			layer.closeAll();
			if (data['code'] == 1) {
				//绑定公司端口
				get_bd_channel(data.data.ch_list,data.data.ch_list_checked);
			} else {
				layer.msg(data['msg'], { icon : 5 });
			}
		});
	}
	
	function get_bd_channel(da,checked){
		transfer.render({
			elem: '#test5'
			,data: da
			,title: ['选择端口', '选中端口']
			,showSearch: true
			,id: 'demo2'
			,value:checked
			,onchange: function(obj, index){
				get_data()
			}
		})
		get_data();
	}
    function get_data(){
        var getData = transfer.getData('demo2');
        var str;
        $.each(getData, function(k,v){
            if(k > 0){
                str += ','+v.value;
            }else{
                str = v.value;
            }
		})
		$("input[name=channel_ids]").val(str);
        
    }
</script>
